//
//  QDJFViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/30.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "QDJFViewController.h"

#import "QDJFCell.h"
@interface QDJFViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation QDJFViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    [self showNav:@"签到积分"];
    [self loadData];
    [self loadUI];
    
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 110)];
    headView.backgroundColor = [UIColor whiteColor];
    _tableView.tableHeaderView = headView;
    
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"矢量智能对象"]];
    [headView addSubview:imgView];
    [imgView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(headView.centerY);
        make.left.equalTo(headView.left).offset(30);
    }];
    
    UILabel *lab1 = [[UILabel alloc] init];
    lab1.text = @"我的积分：";
    lab1.textColor = COLOR_RGB(38, 38, 38, 1);
    [headView addSubview:lab1];
    [lab1 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgView.right).offset(8);
        make.top.equalTo(imgView.top).offset(4);
    }];
    
    
    UILabel *lab2 = [[UILabel alloc] init];
    lab2.text = @"60";
    lab2.font = [UIFont boldSystemFontOfSize:16.0];
    [headView addSubview:lab2];
    [lab2 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lab1.right).offset(0);
        make.top.equalTo(imgView.top).offset(4);
    }];
    
    UILabel *lab3 = [[UILabel alloc] init];
    lab3.text = @"已签到";
    lab3.textColor = [UIColor darkGrayColor];
    lab3.font = [UIFont systemFontOfSize:14.0];
    [headView addSubview:lab3];
    [lab3 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgView.right).offset(8);
        make.bottom.equalTo(imgView.bottom).offset(-4);
    }];
    
    UIButton *btnQD = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnQD setTitle:@"已签到" forState:UIControlStateNormal];
    [btnQD setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btnQD.titleLabel.font = [UIFont systemFontOfSize:15.0];
    btnQD.backgroundColor = COLOR_RGB(255, 201, 107, 1);
    btnQD.layer.cornerRadius = 10.0;
    [btnQD addTarget:self action:@selector(clickQD) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:btnQD];
    [btnQD makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(70);
        make.height.equalTo(30);
        make.centerY.equalTo(imgView.centerY);
        make.right.equalTo(headView.right).offset(-20);
    }];
    
}
//签到功能
- (void)clickQD{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/userSign",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"签到功能res:%@",responseObject);
        //NSString *state = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"status"] integerValue]];
        
        
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}

#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"Cell";
    QDJFCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"QDJFCell" owner:nil options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60.0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
    view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
    
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(16, 10, 80, 20)];
    lab.text = @"签到记录";
    lab.font = [UIFont systemFontOfSize:15.0];    
    
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0;
}
//签到详情
- (void)loadData{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/signinDetails",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"签到详情res:%@",responseObject);
        //NSString *state = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"status"] integerValue]];
        
        
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
